3 include_once ( "LogPage.php" ) ;
4 include_once ( "Feed.php" );
6 # This is a class for doing query pages; since they're almost all the same,
7 # we factor out some of the functionality into a superclass, and let
8 # subclasses derive from it.
11 # Subclasses return their name here. Make sure the name is also
12 # specified in Language.php, both in the $wgValidSpecialPagesEn
13 # variable, and as a language message param.
19 # Subclasses return a SQL query here.
21 function getSQL( $offset, $limit ) {
25 # Is this query expensive (for some definition of expensive)? Then we
26 # don't let it run in miser mode. $wgDisableQueryPages causes all query
27 # pages to be declared expensive. Some query pages are always expensive.
28 function isExpensive( ) {
29 global $wgDisableQueryPages;
30 return $wgDisableQueryPages;
33 # Formats the results of the query for display. The skin is the current
34 # skin; you can use it for making links. The result is a single row of
35 # result data. You should be able to grab SQL results off of it.
37 function formatResult( $skin, $result ) {
41 # This is the actual workhorse. It does everything needed to make a
42 # real, honest-to-gosh query page.
44 function doQuery( $offset, $limit ) {
45 global $wgUser, $wgOut, $wgLang, $wgMiserMode;
47 $sname = $this->getName();
48 $fname = get_class($this) . "::doQuery";
50 $wgOut->setSyndicated( true );
52 if ( $this->isExpensive( ) ) {
53 $vsp = $wgLang->getValidSpecialPages();
54 $logpage = new LogPage( "!" . $vsp[$sname] );
55 $logpage->mUpdateRecentChanges
= false;
58 $logpage->showAsDisabledPage();
63 $sql = $this->getSQL( $offset, $limit );
65 $res = wfQuery( $sql, DB_READ
, $fname );
67 $num = wfNumRows($res);
69 $sk = $wgUser->getSkin( );
71 $top = wfShowingResults( $offset, $num);
72 $wgOut->addHTML( "<p>{$top}\n" );
74 # often disable 'next' link when we reach the end
75 if($num < $limit) { $atend = true; } else { $atend = false; }
77 $sl = wfViewPrevNext( $offset, $limit , $wgLang->specialPage( $sname ), "" ,$atend );
78 $wgOut->addHTML( "<br />{$sl}</p>\n" );
80 $s = "<ol start='" . ( $offset +
1 ) . "'>";
81 while ( $obj = wfFetchObject( $res ) ) {
82 $format = $this->formatResult( $sk, $obj );
83 $s .= "<li>{$format}</li>\n";
87 $wgOut->addHTML( $s );
88 $wgOut->addHTML( "<p>{$sl}</p>\n" );
92 if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
93 $logpage->replaceContent( $s );
97 # Similar to above, but packaging in a syndicated feed instead of a web page
98 function doFeed( $class = "" ) {
99 global $wgFeedClasses;
100 global $wgOut, $wgLanguageCode, $wgLang;
101 if( $class == "rss" ) {
108 $sql = $this->getSQL( 0, 50 );
109 $res = wfQuery( $sql, DB_READ
, "QueryPage::doFeed" );
110 while( $obj = wfFetchObject( $res ) ) {
111 $item = $this->feedResult( $obj );
112 if( $item ) $feed->outItem( $item );
114 wfFreeResult( $res );
123 # Override for custom handling. If the titles/links are ok, just do feedItemDesc()
124 function feedResult( $row ) {
125 if( isset( $row->cur_title
) ) {
126 $title = Title
::MakeTitle( $row->cur_namespace
, $row->cur_title
);
127 } elseif( isset( $row->old_title
) ) {
128 $title = Title
::MakeTitle( $row->old_namespace
, $row->old_title
);
129 } elseif( isset( $row->rc_title
) ) {
130 $title = Title
::MakeTitle( $row->rc_namespace
, $row->rc_title
);
136 if( isset( $row->cur_timestamp
) ) {
137 $date = $row->cur_timestamp
;
138 } elseif( isset( $row->old_timestamp
) ) {
139 $date = $row->old_timestamp
;
140 } elseif( isset( $row->rc_cur_timestamp
) ) {
141 $date = $row->rc_cur_timestamp
;
145 $this->feedItemDesc( $row ),
146 $title->getFullURL(),
148 $this->feedItemAuthor( $row ) );
154 function feedItemDesc( $row ) {
156 if( isset( $row->cur_comment
) ) {
157 $text = $row->cur_comment
;
158 } elseif( isset( $row->old_comment
) ) {
159 $text = $row->old_comment
;
160 } elseif( isset( $row->rc_comment
) ) {
161 $text = $row->rc_comment
;
163 $text = htmlspecialchars( $text );
165 if( isset( $row->cur_text
) ) {
166 $text = "<p>" . htmlspecialchars( wfMsg( "summary" ) ) . ": " . $text . "</p>\n<hr />\n<div>" .
167 nl2br( $row->cur_text
) . "</div>";;
172 function feedItemAuthor( $row ) {
173 $fields = array( "cur_user_text", "old_user_text", "rc_user_text" );
174 foreach( $fields as $field ) {
175 if( isset( $row->$field ) ) return $row->field
;
180 function feedTitle() {
181 global $wgLanguageCode, $wgSitename, $wgLang;
182 $pages = $wgLang->getValidSpecialPages();
183 $title = $pages[$this->getName()];
184 return "$wgSitename - $title [$wgLanguageCode]";
187 function feedDesc() {
188 return wfMsg( "fromwikipedia" );
193 $title = Title
::MakeTitle( NS_SPECIAL
, $this->getName() );
194 return $title->getFullURL();
198 # This is a subclass for very simple queries that are just looking for page
199 # titles that match some criteria. It formats each result item as a link to
202 class PageQueryPage
extends QueryPage
{
204 function formatResult( $skin, $result ) {
205 return $skin->makeKnownLink( $result->cur_title
, "" );